//
//  MCDeliveryInTimeView.swift
//  StoreManage
//
//  Created by MC on 2017/12/28.
//  Copyright © 2017年 MC. All rights reserved.
//

import UIKit

class MCDeliveryInTimeView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(dismissEvent))
        self.addGestureRecognizer(tap)
        
        
        backgroundColor = UIColor.init(white: 0, alpha: 0.4)
        
        self.addSubview(whiteView)
        whiteView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.bottom.equalTo(-10)
            make.height.equalTo(480)
        }
        

        whiteView.addSubview(confirmButton)
        confirmButton.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.bottom.equalTo(-20)
            make.height.equalTo(32)
        }

        whiteView.addSubview(titleLabel)
        titleLabel.snp.remakeConstraints { (make) ->Void in
            make.centerX.equalTo(whiteView)
            make.height.equalTo(50)
            make.top.equalTo(whiteView)
        }
        
        
        let datePickerW : CGFloat = 150
        let margin = (MCScreenWidth - datePickerW * 2) / 4;
        
        whiteView.addSubview(beginDatePicker)
        beginDatePicker.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(margin)
            make.bottom.equalTo(confirmButton.snp.top).offset(-10)
            make.size.equalTo(CGSize.init(width: datePickerW, height: 160))
        }
        
        whiteView.addSubview(endDatePicker)
        endDatePicker.snp.remakeConstraints { (make) ->Void in
            make.right.equalTo(-margin)
            make.bottom.equalTo(confirmButton.snp.top).offset(-10)
            make.size.equalTo(CGSize.init(width: datePickerW, height: 160))
        }
        
        
        
        whiteView.addSubview(beginLabel)
        beginLabel.snp.remakeConstraints { (make) ->Void in
            make.centerX.equalTo(beginDatePicker)
            make.height.equalTo(15)
            make.top.equalTo(beginDatePicker.snp.top).offset(-15)
        }
        
        
        whiteView.addSubview(endLabel)
        endLabel.snp.remakeConstraints { (make) ->Void in
            make.centerX.equalTo(endDatePicker)
            make.height.equalTo(15)
            make.top.equalTo(endDatePicker.snp.top).offset(-15)
        }
        
        
        whiteView.addSubview(thirdStepLabel)
        thirdStepLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.bottom.equalTo(beginLabel.snp.top).offset(-10)
            make.height.equalTo(30)
        }
        
        whiteView.addSubview(secondStepView)
        secondStepView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.bottom.equalTo(thirdStepLabel.snp.top).offset(-10)
            make.height.equalTo(30)
        }

        whiteView.addSubview(firstStep_timeView)
        firstStep_timeView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(25)
            make.right.equalTo(-15)
            make.bottom.equalTo(secondStepView.snp.top).offset(-10)
            make.height.equalTo(30)
        }

        whiteView.addSubview(firstStep_distanceView)
        firstStep_distanceView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(25)
            make.right.equalTo(-15)
            make.bottom.equalTo(firstStep_timeView.snp.top).offset(0)
            make.height.equalTo(30)
        }

        whiteView.addSubview(firstStepLabel)
        firstStepLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.bottom.equalTo(firstStep_distanceView.snp.top).offset(-10)
            make.height.equalTo(30)
        }

    }
    
    @objc func dismissEvent() {
        self.removeFromSuperview()
    }
    
    @objc func whiteViewEvent() {
        self.endEditing(true)
    }

    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    lazy var whiteView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.white
        view.layer.cornerRadius = 10
        view.layer.masksToBounds = true
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(whiteViewEvent))
        view.addGestureRecognizer(tap)

        return view
    }()
    
    
    lazy var confirmButton: UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.layer.cornerRadius = 18
        button.layer.masksToBounds = true
        button.backgroundColor = UIColor.MCMain
        button.titleLabel?.font = MCFont(14)
        button.setTitle("保存", for: UIControlState.normal)
        button.setTitleColor(UIColor.white, for: UIControlState.normal)
        return button
    }()
    
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(20)
        label.textColor = UIColor.black
        return label
    }()
    
    
    lazy var beginLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(14)
        label.textColor = UIColor.black
        label.text = "开始时间"
        return label
    }()
    
    
    lazy var endLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(14)
        label.text = "结束时间"
        label.textColor = UIColor.black
        return label
    }()
    
    lazy var beginDatePicker: UIDatePicker = {
        let pickerView = UIDatePicker.init()
        pickerView.datePickerMode = UIDatePickerMode.time
        return pickerView
    }()
    
    lazy var endDatePicker: UIDatePicker = {
        let pickerView = UIDatePicker.init()
        pickerView.datePickerMode = UIDatePickerMode.time
        return pickerView
    }()
    
    
    lazy var firstStepLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(14)
        label.text = "第一步: 设置及时送的配送范围和时间"
        return label
    }()
    
    lazy var firstStep_distanceView: MCDeliveryInTimeItemView = {
        let view = MCDeliveryInTimeItemView()
        view.titleLabel.text = "送达范围 (公里)"
        view.countTextField.text = "2"
        return view
    }()

    lazy var firstStep_timeView: MCDeliveryInTimeItemView = {
        let view = MCDeliveryInTimeItemView()
        view.titleLabel.text = "送达所需时间 (分钟)"
        view.countTextField.text = "2"
        return view
    }()

    lazy var secondStepView: MCDeliveryInTimeItemView = {
        let view = MCDeliveryInTimeItemView()
        view.titleLabel.text = "第二步: 设置及时送的配送费 (元)"
        view.countTextField.text = "2"
        return view
    }()

    lazy var thirdStepLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(14)
        label.text = "第三步: 设置及时送的服务时间"
        return label
    }()

}
